﻿using System.Windows.Input;
using Peter.Common;
using Peter.Common.Tree;

namespace Peter.Sdw.Logic
{
   /// <summary>
   /// A base view model for several of our view models.
   /// </summary>
   public class BaseModel : ModelTreeViewItem
   {
      private bool m_IsLoading;
      private RelayCommand m_CmdDelete;

      /// <summary>
      /// Initializes a new base model.
      /// </summary>
      /// <param name="parent">The parent model.</param>
      protected BaseModel (ModelTreeViewItem parent)
         : base (parent, true) { }

      /// <summary>
      /// Gets the id of the passage entry.
      /// </summary>
      public int Id { get; set; }

      /// <summary>
      /// Gets or Sets if it is ok to send any updates to the server.
      /// </summary>
      public bool OkToUpdate { get; set; }

      /// <summary>
      /// Gets or Sets if we are loading data.
      /// </summary>
      public bool IsLoading
      {
         get { return this.m_IsLoading; }
         set
         {
            this.m_IsLoading = value;
            this.RaisePropertyChanged ("IsLoading");
         }
      }

      /// <summary>
      /// Gets the delete command.
      /// </summary>
      public ICommand DeleteCommand
      {
         get { return this.m_CmdDelete ?? (this.m_CmdDelete = new RelayCommand (this.OnDelete, this.CanDelete)); }
      }

      /// <summary>
      /// Checks to see if this item can be deleted or not.
      /// </summary>
      /// <param name="obj">Command parameter.</param>
      protected virtual bool CanDelete (object obj) { return false; }

      /// <summary>
      /// Deletes this item.
      /// </summary>
      /// <param name="obj">Command parameter.</param>
      protected virtual void OnDelete (object obj) { }
   }
}
